package tracing;

import java.io.IOException;
import java.util.Vector;
import wdmsim.Simulator;
import events.RouteRequestEvent;

public class Statistic {

	protected static Statistic singletonObject;
	private int accepts;
	private int blocks;
	private int crankbacks;
	private long setupTime;
	private int updateMessages;
	private int insertedFlows;
	Vector<Long> blockedCalls;
	Vector<Long> crankbackedCalls;
	 
	public Statistic() {
		this.accepts = 0;
		this.blocks = 0;
		this.crankbacks = 0;
		this.setupTime = 0;
		this.updateMessages = 0;
		this.insertedFlows = 0;
		this.blockedCalls = new Vector<Long>();
		this.crankbackedCalls = new Vector<Long>();
	}
	
	public static synchronized Statistic getStatisticObject() throws IOException {
    	if (singletonObject == null) 
    		singletonObject = new Statistic();
    	return(singletonObject);
    }
	
	
	public int getAccepts() {
		return accepts;
	}

	public void setAccepts(int accepts) {
		this.accepts = accepts;
	}

	public int getBlocks() {
		return blocks;
	}

	public void setBlocks(int blocks) {
		this.blocks = blocks;
	}

	public int getCrankbacks() {
		return crankbacks;
	}

	public void setCrankbacks(int crankbacks) {
		this.crankbacks = crankbacks;
	}

	public long getSetupTime() {
		return setupTime;
	}

	public int getUpdateMessages() {
		return updateMessages;
	}
	
	public int getInsertedFlows() {
		return insertedFlows;
	}
	
	public void setSetupTime(long setupTime) {
		this.setupTime = setupTime;
	}

	public Vector<Long> getBlockedCalls() {
		return blockedCalls;
	}

	public void setBlockedCalls(Vector<Long> blockedCalls) {
		this.blockedCalls = blockedCalls;
	}
	
	public Vector<Long> getCrankbackedCalls() {
		return crankbackedCalls;
	}

	public void setcrankbackedCalls(Vector<Long> crankbackedCalls) {
		this.crankbackedCalls = crankbackedCalls;
	}

	/**
	 * 
	 * @param event
	 */
	public void blockedCall() {
		blocks++;
		blockedCalls.add(Simulator.CURRENT_TIME);
	}

	/**
	 * 
	 * @param event
	 */
	public void lightpathCreated(RouteRequestEvent event) {
		accepts++;
		setupTime += (Simulator.CURRENT_TIME - event.getFlow().getRequestArrivalTime());
	}
	
	public void addCranks(RouteRequestEvent event) {
		crankbacks++;
		if(!crankbackedCalls.contains(event.getFlow().getId())) {
			crankbackedCalls.add(event.getFlow().getId());
		}
	}

	/**
	 * 
	 */
	public void updateMessage() {
		updateMessages++;
	}

	/**
	 * @param event
	 */
	public void flowInserting(RouteRequestEvent event) {
		insertedFlows++;
	}
}
